<%@ page contentType="text/html; charset=utf-8" %>
<%@ include file="/WEB-INF/views/cover/base-param.jsp" %>
<%@ taglib prefix="primus" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fc" tagdir="/WEB-INF/tags/form" %>
<%@ taglib prefix="btn" tagdir="/WEB-INF/tags/btn" %>
<c:set var="canEdit" value="True"/>
<c:set var="canDelete" value="True"/>
<%--<sec:authorize access="hasRole('OPT_HOMEPAGE_EDIT')"></sec:authorize>--%>
<%--<sec:authorize access="hasRole('OPT_HOMEPAGE_DELETE')"></sec:authorize>--%>

<primus:page title="首页列表">
     <jsp:attribute name="script">
         <script type="application/javascript">
             <%--<c:if test="${canDelete}">--%>
             //删除首页
             function deleteMenu(id, name) {
                 if (confirm("确定要删除首页:" + name + " 吗？")) {
                     $.ajax({
                         url: "${webroot}/management/homepage/delete",
                         type: "post",
                         dataType: "text",
                         data: {coverId: id},
                         success: function (result) {
                             alert("删除成功");
                             window.location.href='management/homepage';
                         },
                         error: function () {
                             alert("操作失败");
                             return false;
                         }
                     });
                 } else {
                     //取消删除
                     return false;
                 }
             }

             function doClone() {
                 $.post("${webroot}/management/homepage/clone.do", $('.clone.modal form').serialize(), function (result) {
                     if (result) {
                         window.location.href='${webroot}/management/homepage/'+result;
                     }
                 });
             }

             $(function () {

                 $(".cover-clone-btn").click(function () {
                     $('.clone.modal').modal('show');
                 });
             });
             <%--</c:if>--%>
         </script>
    </jsp:attribute>
    <jsp:body>
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="welcome.do">
                        首页
                    </a>
                </li>
                <li>
                    首页管理
                </li>
                <li class="active">
                    首页列表
                </li>
            </ul>
        </div>
        <div class="page-content">
            <table width="100%" border="0" cellpadding="0" cellspacing="0" height="100%" style="margin-bottom:65px">
                <tr>
                    <td valign="top" class="mainContent">
                        <table class="navigation" border="0" cellpadding="0" cellspacing="0" width="100%" height="30">
                            <tr>
                                <td align="right">
                                    <c:if test="${canEdit}">
                                        <button class="btn btn-primary" onclick="location='management/homepage/new'">&nbsp;&nbsp;新建首页&nbsp;&nbsp;</button>
                                        <span class="ui tiny primary button cover-clone-btn">
                                <i class="fa fa-copy"></i>
                                <span>克隆</span>
                            </span>
                                    </c:if>
                                </td>
                            </tr>
                        </table>
                        <c:if test="${not empty covers}">
                            <table class="table table-hover table-striped table-bordered mg-top" cellSpacing="0"
                                   cellPadding="0" width="100%" border=0 id="tableMenu">
                                <tr>
                                    <c:if test="${canEdit || canDelete}">
                                        <th>操作</th>
                                    </c:if>
                                    <th>显示顺序</th>
                                    <th>名称</th>
                                    <th>描述</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                <c:forEach items="${covers}" var="cover" varStatus="status">
                                    <tr class="r${status.count%2}">
                                        <c:if test="${canEdit || canDelete}">
                                            <td>
                                                <c:if test="${canEdit}">
                                                    <a href="javascript:void(0);"
                                                       onclick="location='${pageContext.request.contextPath}/management/homepage/${cover.id}'"
                                                       class="btn btn-primary" id="editMenu">
                                                        <i class="fa fa-edit" title="修改"></i>
                                                    </a>
                                                </c:if>
                                                <c:if test="${canDelete}">
                                                    <a href="javascript:void(0);"
                                                       onclick="deleteMenu('${cover.id}', '${cover.name}');"
                                                       class="label label-danger label-white middle">
                                                        <i class="fa fa-trash" title="删除"></i>
                                                    </a>
                                                </c:if>
                                            </td>
                                        </c:if>
                                        <td>${cover.index}</td>
                                        <td>${cover.name}</td>
                                        <td>${cover.description}</td>
                                        <td>${cover.status}</td>
                                        <td>
                                            <a href="${pageContext.request.contextPath}/covers/${cover.id}/preview.do"
                                               target="_blank">
                                                <i class="fa fa-eye" title="预览"></i>
                                            </a>
                                            <a href="${pageContext.request.contextPath}/covers/${cover.id}/clone.do"
                                               target="_blank">
                                                <i class="fa fa-copy" title="克隆"></i>
                                            </a>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </c:if>
                    </td>
                </tr>
            </table>
                <%--<c:if test="${canEdit}">--%>
            <div class="ui standard clone modal">
                <i class="close icon"></i>
                <div class="header">
                    Cover克隆
                </div>
                <div class="content">
                    <form method="post">
                        <div class="ui form">
                            <div class="field">
                                <label>Cover Json</label>
                                <textarea name="coverJson"></textarea>
                            </div>
                            <div class="filed">
                                <button type="button" onclick="doClone()"
                                        class="ui green right labeled icon button clone-confirm-btn">
                                    确认克隆
                                    <i class="fa checkmark"></i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
                <%--</c:if>--%>
        </div>
    </jsp:body>
</primus:page>
